package com.smarthome.ipc;

import com.smarthome.domain.ipc.IpcRequest;

public class IpcClientMain {

    //
    // private static ResourceBundle resource = ResourceBundle.getBundle("conf/ipc-config");
    // private static IoSession session;
    // private static IoConnector connector;
    private static IpcClientMain instance;

    // private static URL realUrl = null;
    //
    private IpcClientMain() {
    }

    //
    public static IpcClientMain getInstance() throws Exception {
        if (null == instance) {
            // instance = new IpcClientMain();
            // instance.openConnection();
            // instance.initConnection();
        }
        return instance;
    }
     public void sendCommand(IpcRequest request) {
        // String requestStr = CommandExporter.parseJsonForIpcRequest(request);
        // session.write(requestStr);
     }
    // private void openConnection() throws Exception {
    // String host = resource.getString("ipc.base.host");
    // int port = Integer.parseInt(resource.getString("ipc.base.port"));
    // IpcClientHandler clientHandler = new IpcClientHandler();
    // connector = new NioSocketConnector();
    // connector.getFilterChain().addLast("logger", new LoggingFilter());
    // connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));
    // connector.setHandler(clientHandler);
    // ConnectFuture connFuture = connector.connect(new InetSocketAddress(host, port));
    // connFuture.awaitUninterruptibly();
    // session = connFuture.getSession();
    // clientHandler.sessionOpened(session);
    // }
    //
    // private void initConnection() throws Exception {
    // IpcInitRequest request = new IpcInitRequest();
    // request.setCommand(IpcConstants.IPC_COMMAND_INIT);
    // request.setIpcId(IPNetUtils.getLocalMac());
    // sendCommand(request);
    // }
    //
    // private void requestAndRecordIp() throws Exception {
    // if (realUrl == null)
    // new URL("http://118.123.116.251/ipc/recordIp?macAddr=" + IPNetUtils.getLocalMac());
    // // 打开和URL之间的连接
    // URLConnection connection = realUrl.openConnection();
    // // 设置通用的请求属性
    // connection.setRequestProperty("accept", "*/*");
    // connection.setRequestProperty("connection", "Keep-Alive");
    // connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
    // // 建立实际的连接
    // connection.connect();
    // }
    //
    // public void closeConnection() {
    // // 关闭会话，待所有线程处理结束后
    // connector.dispose(true);
    // }
    //
    // public static IoSession getSession() {
    // return session;
    // }
    //
    // public static IoConnector getConnector() {
    // return connector;
    // }
    //
    // public static void setInstance(IpcClientMain instance) {
    // IpcClientMain.instance = instance;
    // }
    //
    // public static void main(String[] args) throws Exception {
    // @SuppressWarnings({ "resource", "unused" })
    // ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");
    // IpcClientMain.getInstance();
    //
    // }
}